class Main{
    public static void main(String[] args) {
        String word = "    foo    bar";
        Solution so = new Solution();
        int ret = so.countSegments(word);
        System.out.println(ret);
    }
}
class Solution {
    public int countSegments(String s) {
        if(s.isEmpty()||s.isBlank())
            return 0;
        int count = 0;
        String[] str = s.trim().split(" +");
        for(String x:str){
            if(x != " ")
                count++;
        }
        return count;
    }
}